#!/bin/sh

# NDK 目录
export ANDROID_NDK=/mnt/nas/work/ffmpeg-build-scripts/android-ndk-r21e
# 编译工具
export TOOLCHAIN_PREFIX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
export SYSTEMROOT=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
# 添加编译工具目录
export PATH=$TOOLCHAIN_PREFIX/bin:$PATH
export CC=aarch64-linux-android21-clang
export CXX=aarch64-linux-android21-clang++
export AR=aarch64-linux-android-ar
export LD=/mnt/nas/work/ffmpeg-build-scripts/android-ndk-r21e/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
export ASM=aarch64-linux-android-as

cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr/local/x265 \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_ANDROID_ARCH_ABI=arm64 \
-DCMAKE_ANDROID_NDK=$ANDROID_NDK \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_SYSTEMROOT=$SYSTEMROOT \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DCMAKE_ASM_COMPILER=$ASM \
-DCMAKE_AR=$AR \
-DCMAKE_BUILD_TYPE=Release \
DCMAKE_SYSTEM_VERSION=21
-DENABLE_SHARED=on -DENABLE_CLI=off ../source





aarch64-linux-android/bin/ld: cannot find -lpthread












1. 交叉编译 Android 使用的 x265
前置条件使用 android-ndk-r21e linux 版本。编译脚本内容如下：

build_x265.sh

rm -rf $(pwd)/x265/build/android
rm -rf $(pwd)/build

mkdir x265/build/android
cp -rf build_script/* x265/build/android

export NDK_ROOT=/home/snake/Android/android-ndk-r21e # 换成自己的实际 NDK 路径
export ANDROID_API_VERSION=21
export NUMBER_OF_CORES=4
export OUTPUT_PREFIX=$(pwd)/build

pushd x265/build/android/armeabi-v7a
bash build.sh
popd

pushd x265/build/android/arm64-v8a
bash build.sh
popd
build_script/armeabi-v7a/build.sh

cmake ../../../source \
  -DCMAKE_SYSTEM_NAME=Android \
  -DCMAKE_SYSTEM_VERSION=${ANDROID_API_VERSION} \
  -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \
  -DCMAKE_ANDROID_NDK=${NDK_ROOT} \
  -DCMAKE_ANDROID_STL_TYPE=c++_static \
  -DNEON_ANDROID=1

sed -i 's/-lpthread/-pthread/g' CMakeFiles/cli.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-shared.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-static.dir/link.txt

make -j${NUMBER_OF_CORES}
make DESTDIR=${OUTPUT_PREFIX}/armeabi-v7a install
build_script/arm64-v8a/build.sh

cmake ../../../source \
  -DCMAKE_SYSTEM_NAME=Android \
  -DCMAKE_SYSTEM_VERSION=${ANDROID_API_VERSION} \
  -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
  -DCMAKE_ANDROID_NDK=${NDK_ROOT} \
  -DCMAKE_ANDROID_STL_TYPE=c++_static \
  -DNEON_ANDROID=1

sed -i 's/-lpthread/-pthread/g' CMakeFiles/cli.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-shared.dir/link.txt
sed -i 's/-lpthread/-pthread/g' CMakeFiles/x265-static.dir/link.txt

make -j${NUMBER_OF_CORES}
make DESTDIR=${OUTPUT_PREFIX}/arm64-v8a install









